//
//  HTGuideViewController.m
//  HeartTravel
//
//  Created by lanou on 15/10/24.
//  Copyright © 2015年 陈文杰. All rights reserved.
//

#import "HTGuideViewController.h"
#import "HTPlayerManager.h"
#import "HTPlayerViewController.h"
#import "HTWishViewController.h"


@interface HTGuideViewController ()

@property (nonatomic, strong) UIButton *cancleButton;
@property (nonatomic, strong) UIImageView *playerImageView;
@property (nonatomic, strong) UIImageView *wishImageView;
@property (nonatomic, strong) NSTimer *timer;

@end

@implementation HTGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self cancleButton];
    [self p_setupViewController];
    [self p_setupPlayerImageView];
    [self p_setupWishImageView];
    
    _timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(timeChange) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
}

- (void)p_setupPlayerImageView {
    
    _playerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"磁盘"]];
    _playerImageView.frame = CGRectMake(50, 170, 100, 100);
    [self.view addSubview:_playerImageView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 280, 100, 30)];
    label.text = @"音乐播放器";
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 170, 100, 140)];
    view.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doTap)];
    [view addGestureRecognizer:tap];
    [self.view addSubview:view];
}

- (void)doTap {
    if ([HTPlayerManager shareManager].avPlayer.rate == 1) {
        [self presentViewController:[HTPlayerViewController sharePlayer] animated:YES completion:^{
        }];
    }
}

- (void)p_setupWishImageView{
    
    _wishImageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-150, 170, 100, 100)];
    _wishImageView.layer.cornerRadius = 50;
    _wishImageView.layer.masksToBounds = YES;
//    _wishImageView.image = [UIImage imageNamed:@"流星雨.jpg"];
    NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
    for (int i = 0; i < 20; i++) {
        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.tiff", i]];
        [arr addObject:image];
    }
    _wishImageView.animationImages = arr;
    [_wishImageView setAnimationDuration:2];
    [_wishImageView setAnimationRepeatCount:0];
    [_wishImageView startAnimating];
    [self.view addSubview:_wishImageView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-150, 280, 100, 30)];
    label.text = @"愿望墙";
    label.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:label];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-150, 170, 100, 140)];
    view.backgroundColor = [UIColor clearColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doTapWishImageView)];
    [view addGestureRecognizer:tap];
    [self.view addSubview:view];
}

- (void)doTapWishImageView {
    
//    [self presentViewController:[HTWishViewController shareWishVC] animated:YES completion:^{
//    }];
    [self.navigationController pushViewController:[HTWishViewController shareWishVC] animated:YES];
}

- (void)p_setupViewController {
    
    UIImageView *fontImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"字体"]];
    fontImageView.frame = CGRectMake(SCREEN_WIDTH/2 - 125, 100, 250, 20);
    [self.view addSubview:fontImageView];
}

- (UIButton *)cancleButton {
    
    if (!_cancleButton) {
        _cancleButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _cancleButton.frame = CGRectMake(SCREEN_WIDTH/2-10, SCREEN_HEIGHT-40, 20, 20);
        [_cancleButton setBackgroundImage:[UIImage imageNamed:@"cancle"] forState:(UIControlStateNormal)];
        [_cancleButton addTarget:self action:@selector(handleCancleButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.view addSubview:_cancleButton];
    }
    return _cancleButton;
}

- (void)handleCancleButtonAction:(id)sender {

    [self dismissViewControllerAnimated:YES completion:^{
    }];
}

- (void)timeChange {
    
    if ([HTPlayerManager shareManager].avPlayer.rate == 1) {
        [UIView animateWithDuration:3 animations:^{
            
            _playerImageView.transform = CGAffineTransformRotate(_playerImageView.transform, M_PI);
        } completion:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
